package suncertify.db.test;

import suncertify.db.DBAccess;
import suncertify.db.SecurityException;

public class LockDeleteUnlockUser extends Thread {

    private DBAccess data;
    private long from;
    private long to;
    private int count;

    public LockDeleteUnlockUser(String name, DBAccess data, long from, long to, int count) {

	super.setName(name);
	this.data = data;
	this.from = from;
	this.to = to;
	this.count = count;
    }

    public void run() {

	long lockCookie = 0;

	for (int iteration = 1; iteration <= this.count; ++iteration) {

	    // Data.log("", "===== LockDeleteUnlock =====  iteration = " + Integer.toString(iteration));

	    for (long recordID = from; recordID <= to; ++recordID) {

		// Data.log("", "================= LockDeleteUnlock RecordID = " + Long.toString(recordID)
		// + " ==================");

		try {
		    lockCookie = this.data.lockRecord(recordID);
		    this.data.deleteRecord(recordID, lockCookie);
		} catch (Exception ex) {
		    // Data.log("", "====== RecordNotFoundException recordID = " + Long.toString(recordID));
		} finally {
		    try {
			this.data.unlock(recordID, lockCookie);
		    } catch (SecurityException e) {
			e.printStackTrace();
		    }
		}
	    }
	}
    }
}
